package com.game.server.message.proto.execute;

import com.comm.ISession;

import com.game.majiang.config.DataManager;
import com.game.majiang.logic.LogicClient;
import com.game.majiang.logic.LogicServer;
import com.game.server.db.entity.XyClubInfo;
import com.game.server.db.entity.XyUnionInfo;
import com.game.server.message.proto.in.AbstractXYunionSerchReq;
import com.game.server.message.proto.out.XYunionSerchRsp;
import com.game.server.message.proto.out.XYunioninfoStruct;

public class XYunionSerchReq extends AbstractXYunionSerchReq {

    @Override
    public void Execute(ISession session) {
        LogicClient client = (LogicClient) LogicServer.getInstance().getClient(session.getId());
        if (client != null&&client.checkClick(msgcode)) {
            XYunionSerchRsp rsp = new XYunionSerchRsp();
            rsp.setIsok(1);
            rsp.setUnionid(this.unionid);
            XyClubInfo clubInfo = DataManager.getInstance().getMapClub().get(this.clubid);
            if (clubInfo!=null && clubInfo.getCreatorid()==client.getUserId()){
                if (clubInfo.getUnionid()==0){
                    XyUnionInfo unionInfo = DataManager.getInstance().getMapUnion().get(this.unionid);
                    if (unionInfo!=null){
                        XYunioninfoStruct unioninfoStruct = new XYunioninfoStruct();
                        unioninfoStruct.setId(unionInfo.getId());
                        unioninfoStruct.setHead(unionInfo.getUnion_head());
                        unioninfoStruct.setName(unionInfo.getUnion_name());
                        unioninfoStruct.setMemberRatio(unionInfo.getRatio());
                        unioninfoStruct.setAllPeopleCount(unionInfo.getPlayerCount());
                        rsp.setUnioninfo(unioninfoStruct);
                        rsp.setIsok(0);
                    }
                }else{
                    rsp.setIsok(2);
                }
            }
            client.Send(rsp);
        }
    }

}
